namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DmPBSPDataAccess
    {
        private WSDmPBSPDataAccess.WSDmPBSPDataAccess wDataAcess = new WSDmPBSPDataAccess.WSDmPBSPDataAccess();
        private SmartSoft.DAL.DmPBSPDataAccess oDataAcess = new SmartSoft.DAL.DmPBSPDataAccess();

        public DmPBSPDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        public void CreateInvoice(string ps_Subsidiary, object pd_Ngay_Ct, object ps_Dien_Giai, object ps_Desc_EN, object ps_Ma_Tte, object ps_UserName, object pi_Posted, object pb_Locked, DataTable poDetail)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.CreateInvoice(ps_Subsidiary, pd_Ngay_Ct, ps_Dien_Giai, ps_Desc_EN, ps_Ma_Tte, ps_UserName, pi_Posted, pb_Locked, poDetail);
            }
            else
            {
                oDataAcess.CreateInvoice(ps_Subsidiary, pd_Ngay_Ct, ps_Dien_Giai, ps_Desc_EN, ps_Ma_Tte, ps_UserName, pi_Posted, pb_Locked, poDetail);
            }
        }

        //public bool DeleteDetailRowC(SqlConnection po_Connection, SqlTransaction po_Transaction, object po_KeyCode)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.DeleteDetailRowC(po_Connection, po_Transaction, po_KeyCode == DBNull.Value ? string.Empty : po_KeyCode);
        //    }
        //    else
        //    {
        //        return oDataAcess.DeleteDetailRowC(po_Connection, po_Transaction, po_KeyCode);
        //    }
        //}

        //public bool DeleteDetailRowHS(SqlConnection po_Connection, SqlTransaction po_Transaction, object po_KeyCode)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.DeleteDetailRowHS(po_Connection, po_Transaction, po_KeyCode == DBNull.Value ? string.Empty : po_KeyCode);
        //    }
        //    else
        //    {
        //        return oDataAcess.DeleteDetailRowHS(po_Connection, po_Transaction, po_KeyCode);
        //    }
        //}

        public DataSet GetDataSet(string ps_Subsidiary, object ps_Loai_PB)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSet(ps_Subsidiary, ps_Loai_PB);
            }
            else
            {
                return oDataAcess.GetDataSet(ps_Subsidiary, ps_Loai_PB);
            }
        }

        public DataSet GetDataSetC(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSetC(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2);
            }
            else
            {
                return oDataAcess.GetDataSetC(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2);
            }
        }

        public DataTable GetDetailTable(object ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Sp)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetDetailTable(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp);
            }
            else
            {
                table= oDataAcess.GetDetailTable(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable GetDetailTableC(object ps_KeyCode)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetDetailTableC(ps_KeyCode);
            }
            else
            {
                table= oDataAcess.GetDetailTableC(ps_KeyCode);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable GetDetailTableHS(object ps_KeyCode)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetDetailTableHS(ps_KeyCode);
            }
            else
            {
                table= oDataAcess.GetDetailTableHS(ps_KeyCode);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable GetMasterTable(object ps_Subsidiaries, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Sp_Me)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetMasterTable(ps_Subsidiaries, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp_Me);
            }
            else
            {
                table= oDataAcess.GetMasterTable(ps_Subsidiaries, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp_Me);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable PhanBo_CHSP(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Sp_Me, object ps_Ma_Yt, ref object pi_TTien)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.PhanBo_CHSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp_Me, ps_Ma_Yt, ref pi_TTien);
            }
            else
            {
                table= oDataAcess.PhanBo_CHSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp_Me, ps_Ma_Yt, ref pi_TTien);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public void PhanBo_Delete_All(object ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Sp_Me)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.PhanBo_Delete_All(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp_Me);
            }
            else
            {
                oDataAcess.PhanBo_Delete_All(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp_Me);
            }
        }

        public int PhanBo_DMSP(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_ZPBID, object ps_Tk_154, object ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.PhanBo_DMSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_ZPBID, ps_Tk_154, ps_UserName);
            }
            else
            {
                return oDataAcess.PhanBo_DMSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_ZPBID, ps_Tk_154, ps_UserName);
            }
        }

        public int PhanBo_HSSP(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_ZPBID, object ps_Tk_154, object ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.PhanBo_HSSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_ZPBID, ps_Tk_154, ps_UserName);
            }
            else
            {
                return oDataAcess.PhanBo_HSSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_ZPBID, ps_Tk_154, ps_UserName);
            }
        }

        public int PhanBo_TLSP(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_ZPBID, object ps_Tk_154, object ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.PhanBo_TLSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_ZPBID, ps_Tk_154, ps_UserName);
            }
            else
            {
                return oDataAcess.PhanBo_TLSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_ZPBID, ps_Tk_154, ps_UserName);
            }
        }

        public int PhanBo_TTSP(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object pi_ZPBID, object ps_Tk_154, object ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.PhanBo_TTSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_ZPBID, ps_Tk_154, ps_UserName);
            }
            else
            {
                return oDataAcess.PhanBo_TTSP(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, pi_ZPBID, ps_Tk_154, ps_UserName);
            }
        }

        public void ReAllocation(object ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Sp, object ps_Ma_Yt, object pi_Tien)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.ReAllocation(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp, ps_Ma_Yt, pi_Tien);
            }
            else
            {
                oDataAcess.ReAllocation(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp, ps_Ma_Yt, pi_Tien);
            }
        }

        //public int SaveMasterRowC(SqlConnection po_Connection, SqlTransaction po_Transaction, bool pb_NewChecked, object pd_Ngay_Ct1, object pd_Ngay_Ct2, DataRow row)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.SaveMasterRowC(po_Connection, po_Transaction, pb_NewChecked, pd_Ngay_Ct1, pd_Ngay_Ct2, row);
        //    }
        //    else
        //    {
        //        return oDataAcess.SaveMasterRowC(po_Connection, po_Transaction, pb_NewChecked, pd_Ngay_Ct1, pd_Ngay_Ct2, row);
        //    }
        //}

        //public int SaveMasterRowHS(SqlConnection po_Connection, SqlTransaction po_Transaction, bool pb_NewChecked, DataRow row)
        //{
        //    if (AdapterInstance.IsRemoteConnected)
        //    {
        //        return wDataAcess.SaveMasterRowHS(po_Connection, po_Transaction, pb_NewChecked, row);
        //    }
        //    else
        //    {
        //        return oDataAcess.SaveMasterRowHS(po_Connection, po_Transaction, pb_NewChecked, row);
        //    }
        //}

        public int SaveRow(bool pb_NewChecked, DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRow(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                return oDataAcess.SaveRow(pb_NewChecked, row);
            }
        }

        public bool SaveRowC(bool pb_NewChecked, object pd_Ngay_Ct1, object pd_Ngay_Ct2, DataRow po_MasterDataRow, DataTable po_DetailDataTable)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRowC(pb_NewChecked, pd_Ngay_Ct1, pd_Ngay_Ct2, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(po_MasterDataRow), po_DetailDataTable);
            }
            else
            {
                return oDataAcess.SaveRowC(pb_NewChecked, pd_Ngay_Ct1, pd_Ngay_Ct2, po_MasterDataRow, po_DetailDataTable);
            }
        }

        public bool SaveRowHS(bool pb_NewChecked, DataRow po_MasterDataRow, DataTable po_DetailDataTable)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRowHS(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(po_MasterDataRow), po_DetailDataTable);
            }
            else
            {
                return oDataAcess.SaveRowHS(pb_NewChecked, po_MasterDataRow, po_DetailDataTable);
            }
        }

        public int UpdateProductCosting(object ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Sp_Me, object ps_Tk_154)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.UpdateProductCosting(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp_Me, ps_Tk_154);
            }
            else
            {
                return oDataAcess.UpdateProductCosting(ps_Subsidiary, pd_Ngay_Ct1, pd_Ngay_Ct2, ps_Ma_Sp_Me, ps_Tk_154);
            }
        }
    }
}

